//
//  SortManger.m
//  CNstorm
//
//  Created by 陈家将 on 16/11/22.
//  Copyright © 2016年 chenjiajiang. All rights reserved.
//

#import "SortManger.h"

@implementation SortManger

+ (NSArray *)sortArray:(NSArray *)array type:(FreightSortType)type ByKey:(NSString *)key{
    
    if (type == FreightSortTypeCheaper) {
        // 价格最优排序
        return [self cheaperSortArray:array ByKey:key];
        
    }else if (type == FreightSortTypeFaster) {
        // 速度最快排序
        return [self fasterSortArray:array ByKey:key];
        
    }
    return array;
}

+ (NSArray *)cheaperSortArray:(NSArray *)array ByKey:(NSString *)key{

    NSSortDescriptor *cheaperSortDes = [NSSortDescriptor sortDescriptorWithKey:key ascending:YES];
    NSArray *descriptorArray = [NSArray arrayWithObjects:cheaperSortDes, nil];
    return [array sortedArrayUsingDescriptors:descriptorArray];
    
}

+ (NSArray *)fasterSortArray:(NSArray *)array ByKey:(NSString *)key {
    
    NSSortDescriptor *cheaperSortDes = [NSSortDescriptor sortDescriptorWithKey:key ascending:YES];
    NSArray *descriptorArray = [NSArray arrayWithObjects:cheaperSortDes, nil];
    return [array sortedArrayUsingDescriptors:descriptorArray];
}

@end
